<?php

class McCube_Html_Tabs extends McCube_Html_Abstact{

    protected $_title = '';
    protected $_items = array();
    protected $_itemsSeparator = '';

    public function __construct(){

    }

    public function __toString(){
        return $this->render();
    }

    public function id($id){
        $this->_id = $id;
        return $this;
    }

    public function items($items){
        $this->_items = $items;
        return $this;
    }

    protected function _buildItems(){
        foreach($this->_items as $href => $txt)
            $echo[] = '<li><a href="'.$href.'">'.$txt.'</a></li>';

        return implode($this->_itemsSeparator, $echo);
    }

    public function render(){
        return
            '<div id="'.$this->_id.'">'
                .'<ul>'.$this->_buildItems().'</ul>'
            .'</div>'
            .'<script>$(function() {
            $( "#'.$this->_id.'" ).tabs({idPrefix:"ui-'.$this->_id.'-"}).ajaxComplete(
                function(event, xhr){
                    $.mcCube.tools.ajax.onComplete(xhr);
                }
            );
            });</script>'
        ;
    }

}